//
//  HoldingViewController.m
//  厚积薄发
//
//  Created by 侯振兴 on 14/12/31.
//  Copyright (c) 2014年 侯振兴. All rights reserved.
//

#import "HoldingViewController.h"
#import "LibraryViewController.h"
#import "ListViewController.h"
#import "SearchViewController.h"

#define kBlueColor [UIColor colorWithRed:129/255.0 green: 198/255.0 blue: 221/255.0 alpha: 1.0]

@interface HoldingViewController ()

@property (nonatomic, retain) ListViewController *list;

@end

@implementation HoldingViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"moveListViewController" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"listBack" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"listBackRightNow" object:nil];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self addLibraryViewController];
    [self addListViewController];
    [self createNotification];
    [self createNotification1];
    [self createNotification2];
    [self createBar];

    self.view.backgroundColor = kBlueColor;
    self.navigationController.navigationBar.barTintColor = kBlueColor;
    self.navigationItem.title = @"我的收藏";
    self.navigationController.navigationBarHidden = NO;
}
#pragma mark -
#pragma mark navigationBar
- (void)createBar
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setFrame:CGRectMake(0, 0, 25, 25)];
    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-liebiao.png"] forState:UIControlStateNormal];
    button.alpha = 0.5;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    [button1 setFrame:CGRectMake(0, 0, 30, 30)];
    [button1 setBackgroundImage:[UIImage imageNamed:@"iconfont-sousuo-2.png"] forState:UIControlStateNormal];
    button1.alpha = 0.5;
    [button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button1] autorelease];

}
- (void)buttonAction:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"moveListViewController" object:self userInfo:nil];
}
- (void)buttonAction1:(id)sender
{
    SearchViewController *search = [[SearchViewController alloc] init];
    [search.view setFrame:CGRectMake(0, 200, self.view.frame.size.width, self.view.frame.size.height)];
    [self.navigationController pushViewController:search animated:YES];
    [search release];

}
- (void)addLibraryViewController
{
    LibraryViewController *lib = [[LibraryViewController alloc] init];
    lib.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 49);
    [self addChildViewController:lib];
    [self.view addSubview:lib.view];
    [lib release];
}
- (void)addListViewController
{
    self.list = [[ListViewController alloc] init];
    _list.view.frame = CGRectMake(50 - self.view.frame.size.width, 0, self.view.frame.size.width - 50, self.view.frame.size.height);
    [self addChildViewController:_list];
    [self.view addSubview:_list.view];
    [_list release];
}
//List1秒出现
- (void)createNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(move) name:@"moveListViewController" object:nil];
}
- (void)move
{
    [UIView animateWithDuration:1.0f animations:^{
        _list.view.frame = CGRectMake(0, 0, self.view.frame.size.width - 50, self.view.frame.size.height);
    }];
}
//List1秒回收
- (void)createNotification1
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listBack) name:@"listBack" object:nil];
}
- (void)listBack
{
    [UIView animateWithDuration:0.5f animations:^{
        _list.view.frame = CGRectMake(50 - self.view.frame.size.width, 0, self.view.frame.size.width - 50, self.view.frame.size.height);
    }];
}
- (void)createNotification2
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listBackRightNow) name:@"listBackRightNow" object:nil];
}
- (void)listBackRightNow
{
    [UIView animateWithDuration:0.1f animations:^{
        _list.view.frame = CGRectMake(50 - self.view.frame.size.width, 0, self.view.frame.size.width - 50, self.view.frame.size.height);
    }];
}
//
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
